<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>7_2_2-2-手动停止监听响应式变量</title>
</head>

<body>


  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  <div id="Application">{{a}}</div>
  <script>
    const App = Vue.createApp({
      setup() {
        let a = Vue.ref(1);
        //暂存watchEffect的操作句柄
        let stop = Vue.watchEffect(() => {
          //当变量a变化时，即执行当前函数
          console.log("变量a变化了", a.value);
        });
        a.value = 2;
        //手动停止监听
        stop();
        a.value = 3;
        return {
          a,
        };
      },
    });
    App.mount("#Application");
  </script>
</body>

</html>